import VideoView from '@/views/VideoView.vue'
import Vue from 'vue'
import VueRouter from 'vue-router'

import HomeView from '../views/HomeView.vue'
import VideoInfo1 from '../views/video/VideoInfo1.vue'
import VideoInfo2 from '../views/video/VideoInfo2.vue'

Vue.use(VueRouter)

const routes =
    [
      {
        path: '/',
        name: 'home',
        component: HomeView
      },
      {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
      },
      {
        // 动态路由
        path: '/video/:id',
        name: 'video',
        component: VideoView,
        // 嵌套路由
        children: [
          { path: 'info1', name: 'video-info1', component: VideoInfo1 },
          { path: 'info2', name: 'video-info2', component: VideoInfo2 }
        ],
        props: true
      }
    ]
const router = new VueRouter({
  // 如果不进行修改，默认值是hash
  mode: 'history',
  // 基础地址
  base: process.env.BASE_URL,
  // 路由
  routes
})

// 导航守卫
router.beforeEach((to, from, next) => {
  // console.log('路由触发了')
  next()
})

export default router
